package com.jiantong.work.impl.service;

import com.google.common.base.Throwables;
import com.jiantong.work.impl.manager.ButcherReportManager;
import com.jiantong.work.model.ButcherReport;
import com.jiantong.work.service.ButcherReportWriteService;
import io.terminus.boot.rpc.common.annotation.RpcProvider;
import io.terminus.common.model.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by niufei on 2017/3/22.
 *
 */
@Slf4j
@Service
@RpcProvider
public class ButcherReportWriteServiceImpl implements ButcherReportWriteService{

    private final ButcherReportManager butcherReportManager;

    @Autowired
    public ButcherReportWriteServiceImpl(ButcherReportManager butcherReportManager) {
        this.butcherReportManager = butcherReportManager;
    }

    @Override
    public Response<Map<String , Object>> create(ButcherReport butcherReport , Integer toStatus,List<String> remainderEars) {
        try{
            return Response.ok(butcherReportManager.createButcherReport(butcherReport,toStatus,remainderEars));
        }catch (Exception e){
            log.error("failed to create butcherReport error :{}", Throwables.getStackTraceAsString(e));
            return Response.fail("butcherReport.create.failed");
        }
    }

    @Override
    public Response<Map<String , Object>> update(ButcherReport butcherReport , Integer toStatus,List<String> remainderEars) {
        try{
            return Response.ok(butcherReportManager.updateButcherReport(butcherReport,toStatus,remainderEars));
        }catch (Exception e){
            log.error("failed to update butcherReport error :{}", Throwables.getStackTraceAsString(e));
            return Response.fail("butcherReport.update.failed");
        }
    }
}
